package com.sample.library

import android.app.Application
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.widget.TextView
import cn.bingoogolapple.swipebacklayout.BGASwipeBackHelper
import com.hjq.bar.TitleBar
import com.hjq.bar.initializer.LightBarInitializer
import com.sample.library.toast.ToastUtils
import com.sample.library.util.SPUtils
import com.sample.library.util.ViewUtil
import com.tencent.mmkv.MMKV

object Basic {

    //初始化通用SDK
    fun init(app: Application) {
        ToastUtils.init(app)
        initTitlebar()
        //BGASwipeBackHelper.init(app, null)

        //MMKV.initialize(app)
        //SPUtils.init(app)
    }

    private fun initTitlebar() {

        // 初始化 TitleBar
        TitleBar.setDefaultInitializer(object : LightBarInitializer() {

            override fun getLeftView(context: Context?): TextView? {
                val leftView = super.getLeftView(context)
                context?.let {
                    val drawable: Drawable? = ViewUtil.getRippleDrawable(context)
                    setViewBackground(leftView, drawable)
                }
                getBackIcon(context)?.setTint(Color.parseColor("#333333"))
                return leftView
            }

            override fun getTitleView(context: Context?): TextView? {
                context ?: return null
                return super.getTitleView(context).apply {
                    setTextColor(Color.parseColor("#333333"))
                    setTextSize(20F)
                }
            }
        })

    }

}